package com.boot.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.boot.entity.Cate;
import com.boot.entity.Rooms;
import com.boot.service.CateService;
import com.boot.service.RoomsService;
import com.boot.util.PageHelper;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/rooms" , produces = "text/plain;charset=utf-8")
public class RoomsController extends BaseController {
	// 注入Service 由于标签的存在 所以不需要getter setter
	@Autowired
	private RoomsService roomsService;
	@Autowired
	private CateService cateService;


	// 显示全部数据
	@RequestMapping("getAllRooms.action")
	public String getAllRooms(String number) {
		List<Rooms> roomsList = this.roomsService.getAllRooms();
		PageHelper.getPage(roomsList, "rooms", null, null, 10, number, this.getRequest(), null);
		return "admin/listrooms";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryRoomsByCond.action")
	public String queryRoomsByCond(String cond, String name, String number) {
		Rooms rooms = new Rooms();
		if(cond != null){
			if ("roomsname".equals(cond)) {
				rooms.setRoomsname(name);
			}
			if ("image".equals(cond)) {
				rooms.setImage(name);
			}
			if ("cateid".equals(cond)) {
				rooms.setCateid(name);
			}
			if ("manager".equals(cond)) {
				rooms.setManager(name);
			}
			if ("address".equals(cond)) {
				rooms.setAddress(name);
			}
			if ("contact".equals(cond)) {
				rooms.setContact(name);
			}
			if ("dept".equals(cond)) {
				rooms.setDept(name);
			}
			if ("addtime".equals(cond)) {
				rooms.setAddtime(name);
			}
			if ("contents".equals(cond)) {
				rooms.setContents(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.roomsService.getRoomsByLike(rooms), "rooms", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/queryrooms";
	}

	// 按主键查询数据
	@RequestMapping("getRoomsById.action")
	public String getRoomsById(String id) {
		Rooms rooms = this.roomsService.getRoomsById(id);
		this.getRequest().setAttribute("rooms", rooms);
		List<Cate> cateList = this.cateService.getAllCate();
		this.getRequest().setAttribute("cateList", cateList);
		return "admin/editrooms";
	}

	public RoomsService getRoomsService() { return roomsService; }

	public void setRoomsService(RoomsService roomsService) { this.roomsService = roomsService; }

}
// 程序开发 QQ 709664889 可以付费修改
